<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>更多资讯</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<style type="text/css">
		ul li{
			float: left;
		}
		#flo{
			float: right;
			padding-right: 5px;
		}
		.pageOne,.pageTop,.pageNext,.pageLast{
			border:1px solid #eee;
			margin-right: 20px;
			padding: 5px; 
		}
		#fontsize{
			font-size: 20px;
			margin-left :15px;
			margin-top:10px;
		}
		#addcss{
			float:right;
			margin-top:-45px;
			font-size: 16px;
			margin-right :25px;
			width:100px;
			height:30px;
			text-align: center;
			line-height: 30px;
			
		}
		tr:nth-child(even) {
 			background-color:#eee;
		}
		
	</style>
<script type="text/javascript" src="/EasyBuy/statics/js/jquery-1.8.2.min.js"></script>
  <script type="text/javascript">
  	$(document).ready(function(){
  	$(".me").attr("class","now");
  	//根据时间排序查询所有新闻列表
  		function selectAll(currPageNotransmit){	
  		var ur;
  			if(currPageNotransmit==""||currPageNotransmit==null||currPageNotransmit.length==0){
  				ur="opr=selectAll";
  			}else{
  				ur="opr=selectAll&currPageNo="+currPageNotransmit;
  			}
  			$.getJSON("ConsultationServlet",ur,selectCallBack);
  		}
  		//回调函数
  		function selectCallBack(data){
  			var $table = $("#table").html("");
  			var news;
  			$table.append("<tr><td>文章标题</td><td>创建时间</td><td>操作</td></tr>");
  			
  			for(var i=0;i<data.list.length;i++){
  				news=data.list[i];
  				$table.append("<tr><td id='content'><a class='title' id="+news.id+">"+news.title+"</a></td><td>"+news.date+"</td><td><a class='update' id='"+news.id+"'>修改</a>  |  <a class='del' id="+news.id+">删除 </a></td></tr>");	
  				
  			}
  			$(".title").click(function (){    	 	//点击内容时查看
  				var id=this.id;
				location.href="ConsultationServlet?opr=select&id="+id+"&type=0";
  			});
  			$(".update").click(function (){         //点击修改时进行修改
				var id=this.id;
				location.href="ConsultationServlet?opr=select&id="+id+"&type=1";			
			});
  			
  			
  			$(".pageOne").click(function(){//首页
  				selectAll();
  			});
  			$(".pageTop").click(function(){//上一页
  				selectAll(data.currPageNo-1);
  			});
  			$(".pageNext").click(function(){//下一页
  				selectAll(data.currPageNo+1);
  			});
  			$(".pageLast").click(function(){//最后一页
  				selectAll(data.totalCount);
  			});

			$(".del").click(function(){
				var id=this.id;
				$.get("ConsultationServlet","opr=delete&id="+id,call);
				function call(data){
					if(data=="cg"){
					alert("删除成功");
						location.href="/EasyBuy/backend/news/Member_Member.jsp";
					}else  if(data=="sb"){
						alert("删除失败");
						location.href="/EasyBuy/backend/news/Member_Member.jsp";
					}
				}	
			});	
  		}
  		$("#insert").click(function (){   //进行添加
  			location.href="ConsultationServlet?opr=select&type=3";
  		});
  		
  		$(".m_right").append("<ul id='flo'><li><a class='pageOne'>首页</a></li><li><a class='pageTop'>上一页</a></li><li><a class='pageNext'>下一页</a></li><li><a class='pageLast'>尾页</a></li></ul>");
  			
  		selectAll();
  	});
  </script>
  </head>
  
  <body>

  <div class="i_bg">
    <c:choose>
	  	<c:when test="${empty applicationScope.id}">
	  		<% response.sendRedirect("/EasyBuy/pre/Login.jsp");%>
	  	</c:when>
	  	<c:otherwise>
	  		<%@ include file="../../common/header.jsp" %>
			<%@ include file="../../common/backendHeader.jsp" %>
			 <c:choose>
				<c:when test="${empty applicationScope.type }">
					<% 	request.getRequestDispatcher("../../UserServlet?opr=type&href=Member_Address&href1=order").forward(request, response); %>
				</c:when>
				<c:otherwise>
					<c:if test="${applicationScope.type==1 }">
		  				<%@ include file="../../common/sideMamber.jsp" %> 
					</c:if>
					<c:if test="${applicationScope.type==0 }">
						<%@ include file="../../common/sideUser.jsp" %> 
					</c:if>
				</c:otherwise>
			 </c:choose>
	  	</c:otherwise>
  	</c:choose>
  	
  	
  	<div class="m_right">
  	
	  	<div><p id="fontsize">资讯列表</p><p id="addcss"><a id="insert">添加资讯</a></p></div>
	    <table id="table" border="0" class="order_tab" style="width:930px; text-align:center; margin-bottom:30px; margin-top:20px" cellspacing="0" cellpadding="0">
	   	
	   	</table>
	 </div>
 
	  
  </div> 
    <%@ include file="../../common/footer.jsp" %>
  </body>
</html>

   